<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>async&await</title>
</head>
<body>
  <script>
    
    /*
      Async + Await: 异步问题的终极（最佳）解决方案，并且它要配合Promise使用
      1. 异步代码交给Promise
      2. 在Async函数中配合Await，用同步的方式编写异步代码（串行）
      需求：
        1秒之后，打印1，
        1打印出来之后，2秒之后，打印2，
        2打印出来之后，3秒之后，打印3
    */
    let print = (data, delayTime) => {
      return new Promise(resolve => {
        setTimeout(() => {
          resolve(data)
        }, delayTime * 1000)
      })
    }

    doSomething()

    async function doSomething(){
      let data1 = await print(1, 1)
      console.log(data1)
      let data2 = await print(2, 2)
      console.log(data2)
      let data3 = await print(3, 3)
      console.log(data3)
    }
  </script>
</body>
</html>